﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.ServiceProcess;
using System.Text;

namespace FileSeach
{
    partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。

            FileStream fs = new FileStream(@"C:\TEST.LOG", FileMode.Append, FileAccess.Write, FileShare.Read);
            StreamWriter text = new StreamWriter(fs);
            text.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"START");
            text.Close();
            text.Dispose();
            fs.Close();
            fs.Dispose();
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            FileStream fs = new FileStream(@"C:\TEST.LOG", FileMode.Append, FileAccess.Write, FileShare.Read);
            StreamWriter text = new StreamWriter(fs);
            text.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"STOP");
            text.Close();
            text.Dispose();
            fs.Close();
            fs.Dispose();
        }
    }
}
